package com.cos.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.cos.commons.R;
import com.cos.fegin.api.GoodsService;
import com.cos.vo.GoodsEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;




/**
 * 
 *
 * @author lyc
 * @email 2102@qq.com
 * @date 2021-07-08 15:45:07
 */
@RestController
@RequestMapping("goods/")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 列表
     */
    @RequestMapping("/getGoodsList")
    public String list(ModelMap modelMap){
        List<GoodsEntity> list = goodsService.list();
        modelMap.put("goodsList",list);
        return "/goods/goodsList";
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public String info(@PathVariable("id") Integer id,ModelMap modelMap){
        GoodsEntity info = goodsService.info(id);
        modelMap.put("goods",info);
        return "/goods/updateGoods";
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsEntity goods){
        boolean save = goodsService.save(goods);
            return R.write(save);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsEntity goods){
        boolean update = goodsService.update(goods);
        return R.write(update);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        boolean delete = goodsService.delete(ids);
        return R.write(delete);
    }

}
